package com.t17;

import java.util.Collections;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * Created by xuyiwei on 2018/8/14.
 */
public class SortedSetDemo {
    public static void main(String[] args) {
        SortedSet<String> sortedSet = new TreeSet<String>();
        Collections.addAll(sortedSet,"a b c d e f h i".split(" "));
        //[a, b, c, d, e, f, h, i]
        System.out.println(sortedSet);
        String low = sortedSet.first();
        String hight = sortedSet.last();
        //a
        System.out.println(low);
        //i
        System.out.println(hight);
        Iterator<String> it = sortedSet.iterator();
        for(int i=0;i<5;i++){
            if (i==3) low = it.next();
            if (i==6) hight = it.next();
            else it.next();
        }
        //d
        System.out.println(low);
        //i
        System.out.println(hight);
        //[d, e, f, h]
        System.out.println(sortedSet.subSet(low,hight));
        //[a, b, c, d, e, f, h]
        System.out.println(sortedSet.headSet(hight));
        //[d, e, f, h, i]
        System.out.println(sortedSet.tailSet(low));

    }
}
